package com.dufang.ThreadWaitAndNotify;

/**
 * @ClassName:Consumer
 * @Description 消费这消费包子
 * @Author Administrator
 * @Date 2025/7/7/007 15:54
 * @Version 1.0
 **/
public class Consumer implements Runnable {
  //  BaoZiPu baoZiPu=new BaoZiPu();
    private BaoZiPu baoZiPu;

    public Consumer(BaoZiPu baoZiPu){
        this.baoZiPu=baoZiPu;
    }

    @Override
    public void run() {
        try{
            Thread.sleep(1000L);
        }catch (InterruptedException e){
            throw new RuntimeException(e);
        }
        baoZiPu.getCount();
       /* synchronized (baoZiPu){
            //1、判断flag是否为false,如果是false，证明没有包子，消费线程等待
            if(baoZiPu.isFlag()==false){
                try{
                    baoZiPu.wait();
                }catch (InterruptedException e){
                    throw new RuntimeException(e);
                }
            }

            //2、如果flag为true,证明有包子，开始消费
            baoZiPu.getCount();//可将这里的同步代码放进getCount里面
            //3、改变flag状态，为false,证明消费完了，没有包子了
            baoZiPu.setFlag(false);
            //4、唤醒生产线程
            baoZiPu.notify();
        }*/
    }
}
